package info.techgeek.labs.java5Features.thread.arv;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class CRQToTaskThreadPoolExecuter {
//	private static final Logger LOG = Logger.getLogger(CRQToTaskThreadPoolReader.class);

	private int poolSize = 2;

	private int maxPoolSize = 10;

	private long keepAliveTime = 10;

	private static final CRQToTaskThreadPoolExecuter POOL_EXECUTOR = new CRQToTaskThreadPoolExecuter();
	
	private ThreadPoolExecutor threadPool = null;

	public static CRQToTaskThreadPoolExecuter getInstance() {
		return POOL_EXECUTOR;
	}

	private final ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(5);

	private CRQToTaskThreadPoolExecuter() {
		threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, queue);
////		LOG.warn("***************************************************************");
//		LOG.warn("*   CRQToTaskThreadPoolExecuter ThreadPool Created      *");
//		LOG.warn("*****************************************************************");
	}

	public void runTask(Runnable task) {
		threadPool.execute(task);
		
	}

	public void shutDown() {
		threadPool.shutdown();
	}
}

